# (c) Copyright 2009 Michael Z Goddard. All Rights Reserved. 
# This software is distributed under the MIT license.

class namedtuple(type):
    """
    Simple but duplicated functionality of namedtuple from Python version 2.6
    """
    def __new__(mcls, name, fields):
        base = (tuple,)
        fsplit = fields.split(" ")
        
        d = {
            "__slots__": tuple(),
            "_fields": fsplit
        }
        
        for i, x in enumerate(fsplit):
            d[x] = property((lambda i: lambda self: self[i])(i))
        
        d["__new__"] = eval("lambda cls, " + ",".join(fsplit) + ": tuple.__new__(cls, [" + ",".join(fsplit) + "])")
        d["__repr__"] = lambda self: ("{" + "".join((repr(x) + ": %r, ") for x in self._fields[:-1]) + repr(self._fields[-1]) + ": %r" + "}") % self
        
        return type.__new__(mcls, name, (tuple,), d)
    
